// Learn TypeScript:
//  - https://docs.cocos.com/creator/manual/en/scripting/typescript.html
// Learn Attribute:
//  - https://docs.cocos.com/creator/manual/en/scripting/reference/attributes.html
// Learn life-cycle callbacks:
//  - https://docs.cocos.com/creator/manual/en/scripting/life-cycle-callbacks.html

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {
    @property(cc.Sprite)
    figureSprite: cc.Sprite = null;

    // 花纹的材质
    figureMaterial: cc.MaterialVariant = null;

    // LIFE-CYCLE CALLBACKS:

    onLoad () {
        this.figureMaterial = this.figureSprite.getMaterial(0)
    }

    start () {

    }

    //随机偏移量
    randomOffset() {   
        let strengthFactor = this.random(-10,10)*0.01
        this.figureMaterial.setProperty("strengthFactor", strengthFactor, 0, true)
    }
    
    randomShape() {   
        let speedFactor = this.random(-20,20)
        this.figureMaterial.setProperty("speedFactor", speedFactor, 0, true)
    }

    //随机颜色
    randomColor(){
        this.figureMaterial.setProperty("tarColor1", [this.random(0,1), this.random(0,1), this.random(0,1), 1], 0, true)
    }

    random(min, max) {
        return min + (max-min)*Math.random()
    }
    // update (dt) {}
}
